package com.xyx.uniplugin_bloodoxygen.filters;

import com.xyx.uniplugin_bloodoxygen.datastructs.WaveFormParam;
import com.xyx.uniplugin_bloodoxygen.interfaces.IDataFilter;
import com.xyx.xyxandwxx_ble.async.IAction;

/**
 * 波形数据回调过滤器
 */
public class WaveFormFilter extends IDataFilter {
    /**
     * 搏动数据回调
     */
    private IAction.ActionOne<WaveFormParam[]> paramActionOne;

    /**
     * 构造函数
     *
     *
     */
    public WaveFormFilter( IAction.ActionOne<WaveFormParam[]> event) {
        super((byte)0x0f, (byte) 0x02);
        this.paramActionOne = event;
    }

    @Override
    public void onMessageReceive(byte[] buffer) {
        WaveFormParam [] params = new WaveFormParam[5];
//        int i = 0;
        for(int i = 0; i < params.length; i ++){
            params[i] = new WaveFormParam((buffer[i + 1] & 0x80) != 0, (buffer[i + 1] & 0x7f));
        }

        if(paramActionOne != null){
            try {
                paramActionOne.action(params);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
}
